/**
 * 
 */
package com.cea.papyrus.diagram.component.listener;

import java.util.ArrayList;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.uml2.uml.Interface;

import com.cea.papyrus.core.editpart.IUMLObjectEditPart;
import com.cea.papyrus.core.listener.UmlElementListener;
import com.cea.papyrus.diagram.component.editpart.ComponentEditPart;

/**
 * @author AL090761
 *
 */
public class ComponentListener extends UmlElementListener {

	/**
	 * 
	 */
	private static String TYPE= "type";
	
	
	
	/**
	 * @param editPart
	 */
	public ComponentListener(IUMLObjectEditPart editPart) {
		super(editPart);
	}

	/**
	 * (non-Javadoc).
	 * 
	 * @param notification 
	 * 
	 * @see com.cea.papyrus.common.listener.UmlElementListener#notifyChanged(org.eclipse.emf.common.notify.Notification)
	 */
	@Override
	public void notifyChanged(Notification notification) {
		
		//((PortEditPart)umlEditPart).getUmlElement().getRequireds().clear();
		//((PortEditPart)umlEditPart).getUmlElement().getProvideds().clear();
		ArrayList<Interface> pP=new ArrayList<Interface>();
		if((notification.getFeature()!=null) && (notification.getFeature() instanceof EReference) &&
				((EReference)notification.getFeature()).getName().equals(TYPE)){
			//look for required and provided interfaces.
			
//			Type type=  ((ComponentEditPart)umlEditPart).getUmlElement().getType();
//			if (type instanceof Class){
//				Class clazz= (Class)type;
//				Iterator<Dependency>it =clazz.getClientDependencies().iterator();
//				while (it.hasNext()){
//					Dependency dependency =it.next();
//					if (dependency instanceof InterfaceRealization){
//						pP.add((Interface)((InterfaceRealization)dependency).getSuppliers().get(0));
//					}
//					else{
//						//((PortEditPart)umlEditPart).getUmlElement().getRequireds().add(dependency.getSuppliers().get(0));
//						
//						
//					}
//				}
//			}	
			
			EStructuralFeature sf = ((ComponentEditPart)umlEditPart).getUmlElement().eClass().getEStructuralFeature("provided");
			
		   //((PortEditPart)umlEditPart).getUmlElement().eSet(sf, pP);
			
		}
		super.notifyChanged(notification);
	}	
}
